<template>
  <view class="container screen-width">
    <view class="title">评估报告</view>
    <view class="content-info">
      <view class="list flex items-middle">
        <view class="lable">评估总分：</view>
        <view class="count">{{companyInfo.totalScore || '0'}}分</view>
      </view>
      <view class="list" style="color: red">{{companyInfo.message}}</view>
      <view class="list flex space-between items-middle">
        <view class="lable">受评企业：</view>
        <view class="lable-info">{{companyInfo.companyName || '--'}}</view>
      </view>
      <view class="list flex space-between items-middle">
        <view class="lable">项目名称：</view>
        <view class="lable-info">{{companyInfo.evaluationType || '--'}}</view>
      </view>
    </view>
    <view class="content-info">
      <view class="content-title">
        <text>评估结果</text>
      </view>
      <view class="content-table">
        <table cellspacing="0" cellpadding="0" border="1">
          <tbody>
            <tr>
              <th class="half table-cell text-gray">类别</th>
              <th class="flex-1 table-cell text-gray">得分</th>
            </tr>
            <tr>
              <td class="table-cell">近2年主营业务收入平均增长率</td>
              <td class="table-cell num">{{companyInfo.avgGrowthRateScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">上年度主营业务收入总额占营业收入总额比重</td>
              <td class="table-cell num">{{companyInfo.incomeProportionScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">从事特定细分市场年限</td>
              <td class="table-cell num">{{companyInfo.establishYearsScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">主导产品所属领域</td>
              <td class="table-cell num">{{companyInfo.leadingProductsPatentScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">质量管理水平</td>
              <td class="table-cell num">{{companyInfo.qualityManagementLevelScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">数字化水平</td>
              <td class="table-cell num">{{companyInfo.digitalLevelScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">2021净利润率</td>
              <td class="table-cell num">{{companyInfo.lastYearProfitRateScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">2021资产负债率</td>
              <td class="table-cell num">{{companyInfo.assetsDebtRatioScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">自主研发发明专利</td>
              <td class="table-cell num" rowspan="4">{{companyInfo.patentTotalScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">受让发明专利</td>
            </tr>
            <tr>
              <td class="table-cell">实用新型</td>
            </tr>
            <tr>
              <td class="table-cell">软件著作权</td>
            </tr>
            <tr>
              <td class="table-cell">研发费</td>
              <td class="table-cell num" rowspan="2">{{companyInfo.researchCostScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">研发费占比</td>
            </tr>
            <tr>
              <td class="table-cell">研发人员占比</td>
              <td class="table-cell num">{{companyInfo.researchStaffProportionScore || '0'}}</td>
            </tr>
            <tr>
              <td class="table-cell">研发机构级别</td>
              <td class="table-cell num">{{companyInfo.researchInstitutionalLevelScore || '0'}}</td>
            </tr>
          </tbody>
        </table>
      </view>
    </view>
    <view class="content-info">
      <view class="content-title">
        <text>评估说明</text>
      </view>
      <view>
        认定条件：
        <br />1、从事特定细分市场时间达到2 年以上。
        <br />2、上年度研发费用总额不低于100 万元，且占营业收入总额比重不低于3%。
        <br />3、上年度营业收入总额在1000 万元以上，或上年度营业收入总额在1000 万元以下，但近2 年新增股权融资总额（合格机构投资者的实缴额）达到2000 万元以上。
        <br />4、评价得分达到60 分以上或满足下列条件之一：
        <br />①近三年获得过省级科技奖励，并在获奖单位中排名前三；或获得国家级科技奖励，并在获奖单位中排名前五。
        <br />②近两年研发费用总额均值在1000万元以上。
        <br />③近两年新增股权融资总额（合格机构投资者的实缴额）6000万元以上。
        <br />④近三年进入“创客中国”中小企业创新创业大赛全国500强企业组名单。
      </view>
    </view>
    <view class="declare-btn flex flex-center items-middle">
      <view v-show="showDeclare" class="btn" @click="onPop">精准测评</view>
    </view>
    <van-popup :round="true" v-model="show" closeable @close="onClose">
      <view class="declare-form">
        <view class="list items-middle">
          <view class="name">{{thisYear-3}}年主营业务收入(万元)：</view>
          <input placeholder="请输入" v-model="form.threeYearMainOperatingIncome" />
        </view>
        <view class="list items-middle">
          <view class="name">{{thisYear-2}}年主营业务收入(万元)：</view>
          <input placeholder="请输入" v-model="form.frontYearMainOperatingIncome" />
        </view>
        <view class="list items-middle">
          <view class="name">{{thisYear-1}}年主营业务收入(万元)：</view>
          <input placeholder="请输入" v-model="form.lastYearMainOperatingIncome" />
        </view>
        <view class="list items-middle">
          <view class="name">{{thisYear-1}}年营业收入(万元)：</view>
          <input placeholder="请输入" v-model="form.lastYearOperatingIncome" />
        </view>
        <view class="list items-middle">
          <view class="name">{{thisYear-1}}净利润(万元)：</view>
          <input placeholder="请输入" v-model="form.lastYearNetProfit" />
        </view>
        <view class="list items-middle">
          <view class="name">{{thisYear-1}}总资产(万元)：</view>
          <input placeholder="请输入" v-model="form.lastYearTotalAssets" />
        </view>
        <view class="list items-middle">
          <view class="name">{{thisYear-1}}总负债(万元)：</view>
          <input placeholder="请输入" v-model="form.lastYearTotalLiabilities" />
        </view>
        <view class="btn-box flex flex-end items-middle">
          <view class="btn" @click="onSubmit">提交</view>
        </view>
      </view>
    </van-popup>
    <Festival></Festival>
  </view>
</template>
<script>
import { getDeclare, getDeclareSmall } from "../../util/api/company.js";
import { isWeixin, wxShareConfig } from "@/util/wx.js";
let d = new Date();
let year = d.getFullYear();
export default {
  data() {
    return {
      thisYear: year,
      form: {
        frontYearMainOperatingIncome: 0,
        lastYearMainOperatingIncome: 0,
        lastYearNetProfit: 0,
        lastYearOperatingIncome: 0,
        lastYearTotalAssets: 0,
        lastYearTotalLiabilities: 0,
        threeYearMainOperatingIncome: 0
      },
      companyName: "",
      companyInfo: {},
      show: false,
      showDeclare: false
    };
  },
  onLoad(e) {
    this.companyName = e.name;
    this.getDeclareResult();
  },
  methods: {
    getDeclareResult() {
      uni.showLoading();
      getDeclareSmall({ companyName: this.companyName }).then(res => {
        uni.hideLoading();
        if (res.code === 200) {
          this.companyInfo = res.result;
          this.showDeclare = true;
          if (isWeixin()) {
            this.initShareConfig();
          }
        } else {
          uni.showToast({
            title: res.message,
            duration: 2000,
            icon: "none"
          });
          this.showDeclare = false;
        }
      });
    },
    onPop() {
      this.show = true;
    },
    onClose() {
      this.show = false;
      this.form.frontYearMainOperatingIncome = 0;
      this.form.lastYearMainOperatingIncome = 0;
      this.form.lastYearNetProfit = 0;
      this.form.lastYearOperatingIncome = 0;
      this.form.lastYearTotalAssets = 0;
      this.form.lastYearTotalLiabilities = 0;
      this.form.threeYearMainOperatingIncome = 0;
    },
    onSubmit() {
      let params = [
        {
          value: this.form.threeYearMainOperatingIncome,
          text: `${this.thisYear - 3}年主营业务收入`
        },
        {
          value: this.form.frontYearMainOperatingIncome,
          text: `${this.thisYear - 2}年主营业务收入`
        },
        {
          value: this.form.lastYearMainOperatingIncome,
          text: `${this.thisYear - 1}年主营业务收入`
        },
        {
          value: this.form.lastYearOperatingIncome,
          text: `${this.thisYear - 1}年营业收入`
        },
        {
          value: this.form.lastYearNetProfit,
          text: `${this.thisYear - 1}净利润`
        },
        {
          value: this.form.lastYearTotalAssets,
          text: `${this.thisYear - 1}总资产`
        },
        {
          value: this.form.lastYearTotalLiabilities,
          text: `${this.thisYear - 1}总负债`
        }
      ];
      for (let i = 0; i < params.length; i++) {
        let obj = params[i];
        let reg = /(^[1-9](\d+)?(\.\d{1,3})?$)|(^\d\.\d{1,3}$)/;
        if (!reg.test(obj.value)) {
          uni.showToast({
            title: `${obj.text}不能为0,最多三位小数`,
            duration: 2000,
            icon: "none"
          });
          return;
        }
      }
      let form = Object.assign(this.form, { companyName: this.companyName });
      getDeclareSmall(form).then(res => {
        if (res.code === 200) {
          this.companyInfo = res.result;
          uni.showToast({
            title: "提交成功",
            duration: 2000,
            icon: "none"
          });
          setTimeout(() => {
            this.onClose();
          }, 1000);
        } else {
          uni.showToast({
            title: res.message,
            duration: 2000,
            icon: "none"
          });
          this.onClose();
        }
      });
    },
    initShareConfig() {
      let _this = this;
      let windowurl = window.location.href.split("#")[0];
      uni.request({
        url: "https://oldm.51bmj.cn/WeiXin/GetClientSign", //仅为示例，并非真实接口地址。
        data: {
          rawUrl: windowurl
        },
        dataType: "json",
        header: {
          "X-Requested-With": "XMLHttpRequest"
        },
        method: "GET",
        success: res => {
          if (res.statusCode == 200) {
            let { data } = res;
            let shareInfo = {
              title: "专精特新中小企业测评",
              desc: _this.companyInfo.companyName,
              link: window.location.href
            };
            console.log(99999999, data, shareInfo);
            wxShareConfig(this.$wx, data, shareInfo);
          }
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
page {
  background-color: #6452f2;
}
.container {
  width: 100%;
  padding: 30rpx;
  box-sizing: border-box;
  // height: 100vh;
  overflow: scroll;
  background-color: #6452f2;
  .title {
    width: 100%;
    text-align: center;
    font-size: 48rpx;
    font-weight: bold;
    background: linear-gradient(180deg, #ffffff 40%, #604fef 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  .content-info {
    width: 100%;
    border-radius: 10rpx;
    background: #ffffff;
    padding: 30rpx;
    box-sizing: border-box;
    margin: 20rpx 0;
    .content-title {
      width: 100%;
      text-align: center;
      font-size: 32rpx;
      font-weight: bold;
      margin-bottom: 20rpx;
      text {
        padding: 10rpx;
        background: linear-gradient(180deg, #ffffff 50%, #604fef 100%);
      }
    }
    .list {
      border-bottom: 1rpx solid #eeeeee;
      padding: 20rpx 0;
      font-size: 28rpx;
      .lable {
        color: #aaa;
      }
      .count {
        color: red;
        font-size: 32rpx;
        font-weight: 600;
      }
      .lable-info {
        color: #333;
        text-align: right;
      }
    }
    .list:last-child {
      border-bottom: none;
    }
    .content-table {
      table {
        width: 100%;
        border: 1px solid #eeeeee;
      }
      table tr {
        width: 100%;
      }
      table tr:nth-child(odd) {
        background: #f4feff;
      }
      table tr:first-child {
        background: #f5f6f9;
      }
      table td {
        white-space: wrap;
      }
      .table-cell {
        // height: 30px;
        padding: 10px;
        box-sizing: border-box;
      }
      .num {
        color: coral;
      }
      .half {
        width: 70%;
      }
      .flex-1 {
        width: 30%;
      }
    }
  }
  .declare-btn {
    width: 100%;
    margin-top: 20rpx;
    .btn {
      width: 50%;
      text-align: center;
      height: 60rpx;
      line-height: 60rpx;
      background: #68baa6;
      color: #ffffff;
      border-radius: 10rpx;
    }
  }
  .declare-form {
    width: 550rpx;
    padding: 40rpx 30rpx;
    box-sizing: border-box;
    .list {
      padding: 10rpx 0;
    }
    .name {
      width: 380rpx;
      font-size: 28rpx;
      margin-bottom: 10rpx;
    }
    input {
      border: 1rpx solid #eee;
      border-radius: 10rpx;
      padding: 0 15rpx;
      box-sizing: border-box;
      width: 350rpx;
      height: 58rpx;
      line-height: 58rpx;
    }
    .btn-box {
      width: 100%;
      .btn {
        background: cornflowerblue;
        color: #fff;
        width: 100rpx;
        height: 50rpx;
        line-height: 50rpx;
        border-radius: 10rpx;
        text-align: center;
      }
    }
  }
}
</style>